package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {
    /**
     * 根据分类统计菜品数
     *
     * @param id
     * @return
     */
    @Select("select count(*) from dish group by category_id having category_id = #{id}")
    Integer countByCateId(Long id);

    /**
     * 添加菜品
     *
     * @param dish
     */
    @AutoFill(OperationType.INSERT)
    void insertDish(Dish dish);

    /**
     * 条件查询
     *
     * @param name
     * @param categoryId
     * @param status
     * @return
     */
    Page<DishVO> pageQuery(String name, Integer categoryId, Integer status);

    /**
     * 批量删除菜品
     *
     * @param id
     */
    @Delete("delete from dish where id = #{id};")
    void deleteById(Long id);

    /**
     * 根据id查询菜品
     *
     * @param id
     * @return
     */
    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);

    /**
     * 修改菜品信息
     *
     * @param dish
     */
    @AutoFill(OperationType.UPDATE)
    void updateDish(Dish dish);

    /**
     * 根据分类id查询菜品
     *
     * @param categoryId
     * @return
     */
    @Select("select * from dish where category_id = #{categoryId}")
    List<Dish> getByType(Long categoryId);

    /**
     * 根据套餐id查找菜品信息
     *
     * @param id
     * @return
     */
    @Select("select d.* from setmeal_dish sd left join dish d on sd.dish_id = d.id where setmeal_id = #{id};")
    List<Dish> getBySetmeal(Long id);

    /**
     * 根据分类id查询菜品
     *
     * @param categoryId
     * @return
     */
    List<Dish> list(Long categoryId);
}
